package com.wanggsx.library.base.views;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshKernel;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.RefreshState;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.wang.avi.AVLoadingIndicatorView;
import com.wanggsx.library.R;

public class MyRefreshAnimFooter extends LinearLayout implements RefreshFooter {

    private AVLoadingIndicatorView mAnimationImg;
    Context mContext;
    public MyRefreshAnimFooter(Context context) {
        super(context);
        this.mContext = context;
        setGravity(Gravity.CENTER);
        initView(context);
    }

    /**注意不能为null*/
    @NonNull
    @Override
    public View getView() {
        return this;
    }

    @Override
    public SpinnerStyle getSpinnerStyle() {
        return SpinnerStyle.Translate;
    }


    @Override
    public void setPrimaryColors(int... colors) {

    }

    @Override
    public void onInitialized(RefreshKernel kernel, int height, int extendHeight) {

    }

    @Override
    public void onMoving(boolean isDragging, float percent, int offset, int height, int maxDragHeight) {

    }

    @Override
    public void onReleased(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {

    }

    @Override
    public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) {

    }

    @Override
    public void onStartAnimator(RefreshLayout layout, int height, int extendHeight) {
        start();
    }

    @Override
    public int onFinish(RefreshLayout layout, boolean success) {
        stop();
        return 0;
    }

    @Override
    public boolean isSupportHorizontalDrag() {
        return false;
    }

    @Override
    public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) {

    }

    private void initView(Context context) {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = layoutInflater.inflate(R.layout.loading_anim, this);
        mAnimationImg = view.findViewById(R.id.avloading_loading_anim);
    }


    /**开始*/
    public void start() {
        if (mAnimationImg != null) {
            mAnimationImg.smoothToShow();
        }
    }
    /**结束*/
    public void stop() {
        if (mAnimationImg != null) {
            mAnimationImg.smoothToHide();
        }
    }

    @Override
    public boolean setNoMoreData(boolean noMoreData) {
        return true;
    }
}